import copy

class DefaultDict(dict):
    """Dictionary with a default value for unknown keys.
    By Peter Norvig - http://norvig.com/python-iaq.html"""
    def __init__(self, default):
        self.default = default

    def __getitem__(self, key):
        if key in self:
            return self.get(key)
        return self.setdefault(key, copy.deepcopy(self.default))
